package test;

import java.io.File;
import java.io.FileInputStream;
import java.io.PrintWriter;
import java.util.Iterator;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
//import statements
public class ReadExcelDemo2
{
    public static void main(String[] args)
    {
        try
        {
            FileInputStream file = new FileInputStream(new File("C:\\Users\\Rommel\\workspace\\test\\dashboard\\survey.xlsx"));
 
            //Create Workbook instance holding reference to .xlsx file
            XSSFWorkbook workbook = new XSSFWorkbook(file);
 
            //Get first/desired sheet from the workbook
            XSSFSheet sheet = workbook.getSheetAt(0);
 
            //Iterate through each rows one by one
            Iterator<Row> rowIterator = sheet.iterator();
            
            String text = "";
            String comma;
            if (rowIterator.hasNext())
            {
                Row row = rowIterator.next();
                //For each row, iterate through all the columns
                Iterator<Cell> cellIterator = row.cellIterator();
            	
                while (cellIterator.hasNext())
                {
                    Cell cell = cellIterator.next();
                    
                    if (cellIterator.hasNext())
                    	comma = ",";
                    else
                    	comma = "";
                    
                    text += "data.addColumn('string', '" + cell.getStringCellValue().replace("'", "") + "');\n";
                }
                if (rowIterator.hasNext())
                	text += "\n";
            }
            PrintWriter out = new PrintWriter("C:\\Users\\Rommel\\Desktop\\output2.txt");
            out.println(text);
            out.close();

            file.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}